import { Dialog, Notify } from 'vant'
import { login } from '@/network/login'
import route from '@/router'
const loginModule = {
  namespaced: true,
  state: {
    loginInfo: {}
  },
  mutations: {
    CHANGELOGININFO(state, payload) {
      console.log(state, payload)
      state.loginInfo = payload
    }
  },
  actions: {
    async getLoginInfo(context, payload) {
      const res = await login(payload)
      if (res.meta.status !== 200)
        return Dialog.alert({
          message: res.meta.msg
        })
      Notify({
        message: '登录成功',
        type: 'primary'
      })
      route.push('/center')
      sessionStorage.setItem('token', res.data.token)
      context.commit('CHANGELOGININFO', res.data)
    }
  },
  getters: {}
}

export default loginModule
